package com.kanshu.ksgb.fastread.doudou.module.personal.activity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.TextView
import com.alibaba.android.arouter.facade.annotation.Route
import com.kanshu.ksgb.fastread.doudou.R
import com.kanshu.ksgb.fastread.doudou.app.constants.ARouterConfig
import com.kanshu.ksgb.fastread.doudou.base.baseui.BaseActivity
import com.kanshu.ksgb.fastread.doudou.common.util.ARouterUtils
import com.kanshu.ksgb.fastread.doudou.common.util.Utils
import com.kanshu.ksgb.fastread.doudou.module.personal.bean.BindPhoneInfo
import kotlinx.android.synthetic.main.activity_bind_result.*

@Route(path = ARouterConfig.PERSONAL_BIND_RESULT)
class BindResultActivity :BaseActivity() {

    var mPhone = ""

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_bind_result)
        val info = intent.getParcelableExtra<BindPhoneInfo>("data")
        info?.run {
            mPhone = this.phone;
            val textAccount = String.format(getString(R.string.bind_phone_result_account),this.nickname)
            val textPhone = String.format(getString(R.string.bind_phone_result_phone),Utils.securityShowPhone(this.phone))
            account.text = textAccount
            phoneText.text = textPhone
            total_amount.text = String.format("%1$.2f",this.rmb.toFloat() / 100)
        }
        mTitle.setTitle("绑定手机号")
        update_phone.setOnClickListener{
            var map = HashMap<String, String>()
            map.put("phone", mPhone)
            ARouterUtils.toActivityForResult(this@BindResultActivity, ARouterConfig.PERSONAL_SECURITY_CHECK, map, 100)
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if(resultCode == RESULT_OK && data != null){
            mPhone = data.getStringExtra("phone");
            phoneText.text = String.format(getString(R.string.bind_phone_result_phone), Utils.securityShowPhone(mPhone))
        }
    }

    companion object {
        fun actionStart(activity: Activity,info:BindPhoneInfo) {
            val intent = Intent(activity, BindResultActivity::class.java)
            intent.putExtra("data",info)
            activity.startActivity(intent)
        }
    }
}
